package com.my.fo.strategy.organization.existType;

import cn.hutool.core.io.FileUtil;
import com.my.fo.strategy.organization.inter.OrganizationExistTypeStrategy;
import com.my.fo.strategy.interfaces.StrategyFactoryName;

import java.io.File;

@StrategyFactoryName("leaveLatest")
public class LeaveLatestOrganizationExistTypeStrategy implements OrganizationExistTypeStrategy {

    @Override
    public boolean handlerExist(String inputSrc, String outputSrc) {
        return handlerExist(new File(inputSrc), new File(outputSrc));
    }

    @Override
    public boolean handlerExist(File inputFile, File outputFile) {
        if (inputFile == null) throw new RuntimeException("输入文件不能为空！");
        if (!inputFile.exists()) throw new RuntimeException("输入文件不存在！");
        if (outputFile == null || !outputFile.exists()) return true;
        return FileUtil.lastModifiedTime(inputFile).before(FileUtil.lastModifiedTime(outputFile));
    }

}
